package hu.tortavar2.client.view.product;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.HeadingElement;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class ProductItemSimpleView_ extends Composite {

	private static ProductItemSimpleView_UiBinder uiBinder = GWT
			.create(ProductItemSimpleView_UiBinder.class);

	interface ProductItemSimpleView_UiBinder extends
			UiBinder<Widget, ProductItemSimpleView_> {
	}
			
	public interface SimpleViewPresenter {
		void onClickDetailView(String encodedKey);
	}
	
	public ProductItemSimpleView_(String encodedKey) {
		initWidget(uiBinder.createAndBindUi(this));
		this.key = encodedKey;
		setFields();
	}

	public ProductItemSimpleView_(SimpleViewPresenter presenter, String encodedKey) {
		this(encodedKey);
		this.presenter = presenter;

		
	}

	private SimpleViewPresenter presenter;
	String key;
	@UiField HTMLPanel grid_03;
	@UiField HTMLPanel ribbon;
	@UiField HTMLPanel prodBbox01;
	
	@UiField Anchor anchorToDetailView;
	@UiField Image image;
	@UiField HeadingElement title;
	@UiField SpanElement price;
	@UiField SpanElement available;
	
	private void setFields() {
		grid_03.getElement().setClassName("grid_03");
		ribbon.getElement().setClassName("ribbon");
		prodBbox01.getElement().setClassName("prod-box-01");
		image.getElement().setClassName("prod-image");
	}
	
	public String getKey() {
		return key;
	}
	
	public void setKey(String key) {
		this.key = key;
	}
	
	public void setImageUrl(String url) {
		this.image.setUrl(url);
	}
	
	public void setAchorToDetailView (String url) {
		this.anchorToDetailView.setHref(url);
	}
	
	public void setRibbonType(String ribbonType) {
		this.ribbon.addStyleName(ribbonType);
	}
	
	public void setPrice(String price) {
		this.price.setInnerText(price);
	}
	
	public void setAvailable(String available) {
		this.available.setInnerText(available);
	}
	
	public void setProductTitle(String title) {
		this.title.setInnerText(title);
	}
	
	public String getProductTitle() {
		return this.title.getInnerText();
	}
	
	@UiHandler("anchorToDetailView")
	void onClick(ClickEvent e) {
		presenter.onClickDetailView(this.getKey());
	}
}
